#include "Cube.h"
#include <GL/gl.h>

Cube::Cube()
{
	
}

Cube::Cube(TextureLoader * textureLoader, int aBlockType)
{
	topTexture = textureLoader->textures[TOP][aBlockType];
	sideTexture = textureLoader->textures[SIDE][aBlockType];
	blockType = aBlockType;
	height = 1;
	breadth = 2;
	depth = 2;
}

Cube::~Cube()
{
}

void Cube::render()
{	
	glPushMatrix();
	glTranslatef(xPos, yPos, zPos);
	glBindTexture(GL_TEXTURE_2D, topTexture);
	glBegin(GL_QUADS);
	glColor4f(1, 1, 1, 1);
	//TOP
//	glColor3f(r, g, b);			// Set The Color To Green
	glTexCoord2f(0, 1); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Top)
	glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Top)
	glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Bottom Left Of The Quad (Top)
	glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Bottom Right Of The Quad (Top)
	
	
	//bottom face
//	glColor3f(r * 0.2, g * 0.2, b * 0.2);			// Set The Color To Orange
	glTexCoord2f(1, 1); glVertex3f( 1.0f,-0.5f, 1.0f);			// Top Right Of The Quad (Bottom)
	glTexCoord2f(0, 1); glVertex3f(-1.0f,-0.5f, 1.0f);			// Top Left Of The Quad (Bottom)
	glTexCoord2f(0, 0); glVertex3f(-1.0f,-0.5f,-1.0f);			// Bottom Left Of The Quad (Bottom)
	glTexCoord2f(1, 0); glVertex3f( 1.0f,-0.5f,-1.0f);			// Bottom Right Of The Quad (Bottom)
	
	glEnd();
	
	glBindTexture(GL_TEXTURE_2D, sideTexture);
	
	glBegin(GL_QUADS);
	//front face
//	glColor3f(r * 0.3, g * 0.3, b * 0.3);
	glTexCoord2f(0, 0); glVertex3f(-1, 0.5, 1);
	glTexCoord2f(1, 0); glVertex3f( 1, 0.5, 1);
	glTexCoord2f(1, 1); glVertex3f( 1,-0.5, 1);
	glTexCoord2f(0, 1); glVertex3f(-1,-0.5, 1);
	
	//back face
//	glColor3f(0.0f,0.3f,0.0f);			// Set The Color To Red
	glTexCoord2f(1, 0); glVertex3f( 1.0f,-0.5f,-1.0f);			// Bottom Left Of The Quad (Back)
	glTexCoord2f(1, 1); glVertex3f(-1.0f,-0.5f,-1.0f);			// Bottom Right Of The Quad (Back)
	glTexCoord2f(0, 1); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Back)
	glTexCoord2f(0, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Back)
	
	//right face
//	glColor3f(r * 0.4f, g * 0.4f, b * 0.4f);			// Set The Color To Violet
	glTexCoord2f(1, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Right)
	glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Top Left Of The Quad (Right)
	glTexCoord2f(0, 1); glVertex3f( 1.0f,-0.5f, 1.0f);			// Bottom Left Of The Quad (Right)
	glTexCoord2f(0, 0); glVertex3f( 1.0f,-0.5f,-1.0f);			// Bottom Right Of The Quad (Right)
	
	//left face
//	glColor3f(0.0f,0.4f,0.0f);			// Set The Color To Blue
	glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Top Right Of The Quad (Left)
	glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Left)
	glTexCoord2f(1, 1); glVertex3f(-1.0f,-0.5f,-1.0f);			// Bottom Left Of The Quad (Left)
	glTexCoord2f(0, 1); glVertex3f(-1.0f,-0.5f, 1.0f);			// Bottom Right Of The Quad (Left)
	
	glEnd();
	glPopMatrix();
}
